package com.ruoyi.fitsculpt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fitsculpt.domain.EasyfitExercises;
import com.ruoyi.fitsculpt.service.IEasyfitExercisesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 运动库Controller
 *
 * @author metaee
 * @date 2025-02-27
 */
@Api(tags = "运动库管理")
@RestController
@RequestMapping("/fitsculpt/exercises")
public class EasyfitExercisesController extends BaseController {
    @Autowired
    private IEasyfitExercisesService easyfitExercisesService;

    /**
     * 查询运动库列表
     */
    @ApiOperation("查询运动库列表")
    @GetMapping("/list")
    public TableDataInfo list(EasyfitExercises easyfitExercises) {
        startPage();
        List<EasyfitExercises> list = easyfitExercisesService.selectEasyfitExercisesList(easyfitExercises);
        return getDataTable(list);
    }

    /**
     * 导出运动库列表
     */
    @ApiOperation("导出运动库列表")
    @Log(title = "运动库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EasyfitExercises easyfitExercises) {
        List<EasyfitExercises> list = easyfitExercisesService.selectEasyfitExercisesList(easyfitExercises);
        ExcelUtil<EasyfitExercises> util = new ExcelUtil<EasyfitExercises>(EasyfitExercises.class);
        util.exportExcel(response, list, "运动库数据");
    }

    /**
     * 获取运动库详细信息
     */
    @ApiOperation("获取运动库详细信息")
    @GetMapping(value = "/{exerciseId}")
    public AjaxResult getInfo(@ApiParam(value = "运动库ID", required = true) @PathVariable("exerciseId") Long exerciseId) {
        return success(easyfitExercisesService.selectEasyfitExercisesByExerciseId(exerciseId));
    }

    /**
     * 新增运动库
     */
    @ApiOperation("新增运动库")
    @Log(title = "运动库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EasyfitExercises easyfitExercises) {
        return toAjax(easyfitExercisesService.insertEasyfitExercises(easyfitExercises));
    }

    /**
     * 修改运动库
     */
    @ApiOperation("修改运动库")
    @Log(title = "运动库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EasyfitExercises easyfitExercises) {
        return toAjax(easyfitExercisesService.updateEasyfitExercises(easyfitExercises));
    }

    /**
     * 删除运动库
     */
    @ApiOperation("删除运动库")
    @Log(title = "运动库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{exerciseIds}")
    public AjaxResult remove(@ApiParam(value = "运动库ID数组", required = true) @PathVariable Long[] exerciseIds) {
        return toAjax(easyfitExercisesService.deleteEasyfitExercisesByExerciseIds(exerciseIds));
    }
}
